//
//  ViewController.m
//  TableViewDrag
//
//  Created by max on 2018/10/30.
//  Copyright © 2018年 max. All rights reserved.
//

#import "ViewController.h"
#import "DragTableView.h"
#import "DragScrollView.h"
@interface ViewController ()

@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) NSMutableArray *dataArray;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createData];
    
    [self setupUI];
}

- (void)createData {
    self.dataArray = [NSMutableArray array];
    NSArray *sectionTextArray = @[@"I am just a plain text 😳",
                                  @"I am just a lovely text 😊",
                                  @"I am just a naughty text 😜",
                                  @"I am just a boring text 🙈"];
    for (NSInteger section = 0; section < 4; section ++) {
        NSMutableArray *sectionArray = [NSMutableArray new];
        for (NSInteger row = 0; row < 7; row ++) {
            [sectionArray addObject:[NSString stringWithFormat:@"%@-%ld", sectionTextArray[section], (long)row]];
        }
        [self.dataArray addObject:sectionArray];
    }
}

- (void)setupUI {
    
    self.view.backgroundColor = [UIColor redColor];
    
    CGFloat margin1Width = 45;
    CGFloat margin2Width = 10;
    
    DragScrollView *scrollView = [[DragScrollView alloc] initWithFrame:CGRectMake(margin1Width, 64, self.view.frame.size.width - 2 * margin1Width, self.view.frame.size.height)];
    [self.view addSubview:scrollView];
    
    for (int i = 0; i < self.dataArray.count; i++) {
        DragTableView *tableView = [[DragTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        CGRect frame = tableView.frame;
        frame.size.width = scrollView.frame.size.width - 2 * margin2Width;
        frame.origin.x = (2 * i + 1) * margin2Width + i * frame.size.width;
        tableView.frame = frame;
        tableView.dataArray = self.dataArray[i];
        [scrollView addSubview:tableView];
        [scrollView.contentViews addObject:tableView];
    }
    scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * self.dataArray.count, self.view.frame.size.height);
    self.scrollView = scrollView;    
}


@end
